import json
import os.path
import DB
from Common import *

class GlobalData:
    def __init__(self, logger):
        self.logger = logger
        self.short_names = {}

    def __load_short_names(self, db):        
        args = {'show_delete':0, 'return_raw':0}
        ret = db.getPaymentCategory2(args)
        if ret['errno'] != Error.SUCCESS:
            return ret
        self.short_names = {}
        for item in ret['data']:
            short_names = item['short_names'].split(' ')
            if len(short_names) == 0:
                continue
            for name in short_names:
                self.short_names[name] = (item['cat1_id'], item['cat2_id'])
                
    def load_data(self):
        # 全局数据暂时只有short_names
        # 后续增加新的全局数据时，加载的逻辑单独写在一个函数里
        db = DB.DB(self.logger)
        self.__load_short_names(db)
        
